package com.lmf.mvc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 非异步处理servlet程序：如下
 */
@WebServlet("/comm")
public class CommonServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //解决客户端请求中文乱码
//        req.setCharacterEncoding("UTF-8");
//        //统一浏览器的字符集编码格式：utf-8,解决响应中文乱码
//        resp.setContentType("text/html;charset=UTF-8");
        System.out.println("当前执行线程："+Thread.currentThread());
        try {
            sayHello();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        resp.getWriter().write("hello.........中文......");
        resp.getWriter().println("\nhello lmf.........中文.....");
        System.out.println("当前结束线程："+Thread.currentThread());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    public void sayHello() throws InterruptedException {
        System.out.println("线程睡眠3秒..........");
        Thread.sleep(3000);
    }
}
